<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@include file="../header.inc"%>
    <title>门诊查询</title>
    <style type="text/css">
        body {
            padding-bottom: 40px;
        }
        .sidebar-nav {
            padding: 9px 0;
        }

        @media (max-width: 980px) {
            /* Enable use of floated navbar text */
            .navbar-text.pull-right {
                float: none;
                padding-left: 5px;
                padding-right: 5px;
            }
        }


    </style>
    <script type="text/javascript">
      //初始化pageNo页码为1
      var pageNo=1;
      //初始化pageTotal总页数为0
      var pageTotal = 0;
      //定义“上一页”方法绑定给“上一页”按钮
      function up(){
        if(pageNo==1){
          alert("已经是第一页！");
          return;
        }
        //将页码减1
        pageNo--;
        //调用page()方法时页码已经减1
        page();
      }
      //定义“下一页”方法绑定给“下一页”按钮
      function last() {
        pageNo = pageTotal
        page()
      }
      //定义“下一页”方法绑定给“下一页”按钮
      function down(){
        if(pageNo==pageTotal){
          alert("已经是最后一页！");
          return;
        }
        //将页码加1供page()使用
        pageNo ++;
        page();
      }
      //该方法实现刷新页面的效果，实现页码变动后，将对应页码的数据显示在页面中
      function page(){
        //将页码传递给DataServlet用来处理与该页码相关的jdbc操作
        var path = "/hospital/register/list?pageNo="+pageNo+"&"+$("#registerForm").formSerialize();
        //定义一个异步
        var object={
          url:path,
          type:"get",
          //此时的data数据是data.jsp文件中的所有标签对象
          success:function(data){
            $("#data").html(data);
            //将收到的pageTotal隐藏框的值赋值给pageTotal
            pageTotal = $("#pageTotal").val();
            $("#totalSpan").text($("#total").val());
            $("#pageTotalSpan").text(pageTotal);
          }
        }
        //触发异步
        $.ajax(object);
      }
      //在第一次加载页面时就执行page()显示第一页数据
      page();
      //为了避免点击下一页后搜索功能失效的bug，所以每次搜索时将页码重置为1
      function search(){
        pageNo=1;
        page();
      }

      function deleteById(id) {
        if (!confirm("确认删除该行记录？")) {
          return false;
        }
        //定义一个异步
        var object={
          url:"/hospital/register/deleteById?id="+id,
          type:"get",
          //
          success:function(data){
            alert(data.msg);
            pageNo=1;
            page();
          }
        }
        //触发异步
        $.ajax(object);
      }

      function checkall(checkbox) {
        if($(checkbox).prop('checked')){
          $(".checkAllRegister").attr("checked",true);
        }else{
          $(".checkAllRegister").attr("checked",false);
        }
      }

      function delAll(){
        var ids = "";
        $(".checkAllRegister:checked").each(function () {
          ids=ids+$(this).val()+",";
        })
        if(ids==""){
          alert("请勾选要删除的记录");
          return false;
        }
        ids=ids.substr(0,ids.length-1);

        if (!confirm("确认删除该行记录？")) {
          return false;
        }
        //定义一个异步
        var object={
          url:"/hospital/register/delete?ids="+ids,
          type:"get",
          //
          success:function(data){
            alert(data.msg);
            pageNo=1;
            page();
          }
        }
        //触发异步
        $.ajax(object);

      }
    </script>
</head>
<body>

<form action="${path }hospital/register/list" method="post" id="registerForm" class="definewidth m20">
<table class="table table-bordered table-hover definewidth m10">
    <tr>
        <td width="10%" class="tableleft">病历号：</td>
        <td><input type="text" name="rid" value=""/></td>
		
        <td width="10%" class="tableleft">姓名：</td>
        <td><input type="text"  name="name" value=""/></td>
		
        <td width="10%" class="tableleft">科室：</td>
        <td>
        	<select name="department" id="department">
	        	<option value="" >==请选择==</option>
	        	<option value="1" >急诊科</option>
	        	<option value="2" >儿科</option>
	        	<option value="3" >妇科</option>
	        	<option value="4" >皮肤科</option>
	        	<option value="5" >内分泌科</option>
	        	<option value="6" >牙科</option>
        	</select>
        </td>
    </tr>
    <tr>
		  <td colspan="6">
		  <center>
            <input id="find" name="find" onclick="search()" type="button" class="btn btn-primary" value="查询"/>
			<input name="ret" onclick="$('#registerForm').resetForm()" type="button" class="btn btn-primary" value="清空"/>
            </center>
        </td>
    </tr>
</table>
</form>

<!--声明一个空的div标签用于填充data.jsp文件传过来的标签-->
<div id="data">

</div>
  <table class="table table-bordered table-hover definewidth m10" >
  	<tr><th colspan="5">  
  		<div class="inline pull-right page">
	          <a href="" >首页</a> 
	          <a href="javascript:up()">上一页</a>
	          <a href="javascript:down()" >下一页</a>
	          <a href="javascript:last()" >尾页</a>
			  &nbsp;&nbsp;&nbsp;
			     共<span id="totalSpan" class='current'> </span>条记录
			     <span id="pageTotalSpan" class='current'> </span>页
		</div>
		<div>
		   <button type="button" class="btn btn-success"
                   onclick="window.location.href='/hospital/register/add'">门诊挂号</button>&nbsp;&nbsp;&nbsp;
		   <button type="button" class="btn btn-success" id="delRegister" onclick="delAll()">批量删除</button>
		</div>
	</th></tr>
  </table>
  
</body>
</html>
